Skip to content

Conversation

@joaquimds
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds functionality to change and add multiple data sources for inspector boundary configurations. The key enhancement is the ability to configure multiple data sources per boundary, each with their own columns and settings.

Changes:

  • Added id field to InspectorBoundaryConfig schema for unique identification of boundary configurations
  • Created reusable DataSourceSelectButton component with filtering by area set code
  • Enabled adding/removing/changing data sources in the inspector config tab

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/server/models/MapView.ts Added required id field to inspector boundary config schema
migrations/1769099632447_boundary_config_add_id.ts Migration to add UUID id to existing boundary configs
src/components/DataSourceItem.tsx Exported type DataSourceWithImportInfo for reuse
src/app/map/[id]/components/DataSourceSelectButton.tsx New reusable component for data source selection with modal
src/app/map/[id]/components/inspector/InspectorPanel.tsx Updated styling to fix overflow issues with min-h-0
src/app/map/[id]/components/inspector/InspectorDataTab.tsx Changed key from dataSourceId to id, added check for non-empty columns
src/app/map/[id]/components/inspector/InspectorConfigTab.tsx Added functionality to add/remove data sources with UUID generation
src/app/map/[id]/components/inspector/BoundaryConfigItem.tsx Added data source change/remove capabilities with area set filtering
src/app/map/[id]/components/inspector/BoundaryDataPanel.tsx Added dataSourceId check to enabled condition
src/app/map/[id]/components/controls/VisualisationPanel/VisualisationPanel.tsx Refactored to use new DataSourceSelectButton component

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 94 to 101
const handleDataSourceIdChange = (dataSourceId: string) => {
setSelectedColumns([]);
onUpdate({
...boundaryConfig,
dataSourceId,
columns: [],
});
};
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local state configName is not updated when the data source is changed. This will cause the Name input field to display stale data from the previous data source until the user manually changes it. Consider calling setConfigName when the data source is changed.

Copilot uses AI. Check for mistakes.
Comment on lines 6 to 24
await sql`
UPDATE map_view
SET inspector_config = jsonb_set(
inspector_config,
'{boundaries}',
(
SELECT jsonb_agg(
jsonb_set(
boundary,
'{id}',
to_jsonb(gen_random_uuid()::text)
)
)
FROM jsonb_array_elements(inspector_config->'boundaries') AS boundary
)
)
WHERE inspector_config ? 'boundaries'
AND jsonb_typeof(inspector_config->'boundaries') = 'array'
`.execute(db);
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration may produce a null value when boundaries is an empty array, because jsonb_agg returns null when aggregating zero rows. Consider handling the empty array case by using COALESCE to preserve an empty array instead of setting it to null.

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 40
export async function down(db: Kysely<any>): Promise<void> {
await sql`
UPDATE map_view
SET inspector_config = jsonb_set(
inspector_config,
'{boundaries}',
(
SELECT jsonb_agg(boundary - 'id')
FROM jsonb_array_elements(inspector_config->'boundaries') AS boundary
)
)
WHERE inspector_config ? 'boundaries'
AND jsonb_typeof(inspector_config->'boundaries') = 'array'
`.execute(db);
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The down migration may produce a null value when boundaries is an empty array, because jsonb_agg returns null when aggregating zero rows. Consider handling the empty array case by using COALESCE to preserve an empty array instead of setting it to null.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@joaquimds
Copy link
Member Author

@copilot add COALESCE to the up and down migrations to prevent null values in the array

Copy link
Contributor

Copilot AI commented Jan 22, 2026

@joaquimds I've opened a new pull request, #285, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits January 22, 2026 17:00
Co-authored-by: joaquimds <12935136+joaquimds@users.noreply.github.com>
fix: prevent null boundaries in migration when array is empty
@joaquimds joaquimds merged commit cce2c7a into main Jan 22, 2026
1 check passed
@joaquimds joaquimds deleted the feat/inspector-data branch January 22, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants